#ifndef __PTGUI_REGION_H__
#define __PTGUI_REGION_H__

#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif

typedef struct ptgui_region_data ptgui_region_data_t;

struct ptgui_region_data
{
    rt_uint32_t size;
    rt_uint32_t numRects;
    /* XXX: And why, exactly, do we have this bogus struct definition? */
	/* ptgui_rect_t	rects[size]; in memory but not explicitly declared */
};

typedef struct ptgui_region
{
	ptgui_rect_t          extents;
	ptgui_region_data_t  *data;
}ptgui_region_t;

typedef enum
{
	PTGUI_REGION_STATUS_FAILURE,
	PTGUI_REGION_STATUS_SUCCESS
}ptgui_region_status_t;

/* creation/destruction */

void ptgui_region_init(ptgui_region_t *region);
void ptgui_region_init_rect(ptgui_region_t *region,
	int x, int y, unsigned int width, unsigned int height);
void ptgui_region_init_with_extents(ptgui_region_t *region, ptgui_rect_t *extents);
void ptgui_region_fini (ptgui_region_t *region);

void ptgui_region_translate (ptgui_region_t *region, int x, int y);

ptgui_region_status_t ptgui_region_copy (ptgui_region_t *dest, ptgui_region_t *source);

ptgui_region_status_t ptgui_region_intersect (ptgui_region_t *newReg, ptgui_region_t *reg1, ptgui_region_t *reg2);
ptgui_region_status_t ptgui_region_intersect_rect (ptgui_region_t *newReg, ptgui_region_t *reg1, ptgui_rect_t *rect);
ptgui_region_status_t ptgui_region_union (ptgui_region_t *newReg, ptgui_region_t *reg1, ptgui_region_t *reg2);
ptgui_region_status_t ptgui_region_union_rect(ptgui_region_t *dest, ptgui_region_t *source, ptgui_rect_t* rect);
ptgui_region_status_t ptgui_region_subtract (ptgui_region_t *regD, ptgui_region_t *regM, ptgui_region_t *regS);
ptgui_region_status_t ptgui_region_subtract_rect (ptgui_region_t *regD, ptgui_region_t *regM, ptgui_rect_t* rect);
ptgui_region_status_t ptgui_region_inverse (ptgui_region_t *newReg, ptgui_region_t *reg1, ptgui_rect_t *invRect);

int ptgui_region_num_rects (ptgui_region_t *region);

ptgui_rect_t* ptgui_region_rects (ptgui_region_t *region);

#define PTGUI_REGION_OUT	0
#define PTGUI_REGION_IN		1
#define PTGUI_REGION_PART	2

int ptgui_region_contains_point (ptgui_region_t *region, int x, int y, ptgui_rect_t *box);
int ptgui_region_contains_rectangle (ptgui_region_t *ptgui_region_t, ptgui_rect_t *prect);

int ptgui_region_not_empty (ptgui_region_t *region);
ptgui_rect_t *ptgui_region_extents (ptgui_region_t *region);

ptgui_region_status_t ptgui_region_append (ptgui_region_t *dest, ptgui_region_t *region);
ptgui_region_status_t ptgui_region_validate (ptgui_region_t *badreg, int *pOverlap);

void ptgui_region_reset(ptgui_region_t *region, ptgui_rect_t* rect);
void ptgui_region_empty (ptgui_region_t *region);
void ptgui_region_dump(ptgui_region_t* region);

/* rect functions */
extern ptgui_rect_t ptgui_empty_rect;

void ptgui_rect_moveto(ptgui_rect_t *rect, int x, int y);
void ptgui_rect_moveto_align(ptgui_rect_t *rect, ptgui_rect_t *to, int align);
void ptgui_rect_inflate(ptgui_rect_t *rect, int d);
void ptgui_rect_intersect(ptgui_rect_t *src, ptgui_rect_t *dest);
int  ptgui_rect_contains_point(ptgui_rect_t *rect, int x, int y);
int  ptgui_rect_is_intersect(ptgui_rect_t *rect1, ptgui_rect_t *rect2);

#if defined(__cplusplus) || defined(c_plusplus)
}
#endif

#endif /* _PIXMAN_H_ */
